<template>
	<view class="container">
		<wu-calendar :insert="true" :lunar="true" @change="calendarChange" mode='multiple'
			:selected="selected"></wu-calendar>
		<view class="btn">
			<u-button type="primary" text="保存" @click="ordercreate"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		ordercreate,
		holidaylist
	} from '@/api/holiday.js'
	export default {
		data() {
			return {
				selected: [],
				obj: {},
				multiple: []
			};
		},
		onLoad(e) {
			this.obj = JSON.parse(e.obj)
			this.holidaylist(this.obj.month, this.obj.student_id)
		},
		methods: {
			calendarChange(e) {
				this.multiple = e.multiple
			},
			//获取请假列表用于显示缺勤
			async holidaylist(month, student_id) {
				let res = await holidaylist({
					month,
					student_id
				})
				if (res.code == 200) {
					if (res.data.length != 0) {
						res.data.forEach(item => {
							let obj = {
								date: item.month+'-'+item.day,
								info: '请假',
							}
							this.selected.push(obj)
						})
					}
				} else {
					uni.$u.toast(res.msg);
				}
			},
			//学校列表用于下拉
			async ordercreate() {
				let res = await ordercreate({
					day: this.multiple.toString(),
					student_id: this.obj.student_id
				})
				if (res.code == 200) {
					this.holidaylist(this.obj.month, this.obj.student_id)
				} else {
					uni.$u.toast(res.msg);
				}
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100vw;
		height: 100%;
		padding: 0 20rpx;
		box-sizing: border-box;

		.btn {
			width: 100%;
			margin: 0 auto;
			margin-top: 50rpx;
		}
	}
</style>